home *** CD-ROM | disk | FTP | other *** search
- /*
- FILE: zerocross.c
- PROJECT: Ford grant DSP
- AUTHOR: Ben Denckla
- COMMENT: Collects data on the length between zero-crossings.
- */
-
- #include "aiff.h"
- #include <stdio.h>
- #include <assert.h>
- #include <string.h>
-
- #define BINS 40
- #define BINSIZE 5
-
- int take_input = 1, make_output = 0;
-
- static long histogram[BINS+1] = {0};
-
- void init_process( void ) {
- if ( (ba.com.wdsi != 8) )
- err( "Cannot process a file with this word size" );
- if ( (ba.com.chan != 1) )
- err( "Cannot process a multichannel file" );
- }
-
- void term_process ( void ) {
- #define BARMAX 60
-
- int i, barlen;
- long histmax = 0;
- FILE *f;
- char bar[80];
-
- memset( bar, '*', BARMAX );
-
- f = fopen( "zerocross.out", "w" );
-
- for (i=0; i<BINS; i++)
- if (histogram[i] > histmax) histmax = histogram[i];
-
- fprintf( f, "out of range: %ld\n", histogram[BINS] );
- for (i=0; i<BINS; i++) {
- barlen = (float) BARMAX * histogram[i]/histmax;
- fprintf( f, "[%.3d...%.3d): %.4ld %.*s\n",
- i*BINSIZE, (i+1)*BINSIZE, histogram[i], barlen, bar );
- }
- fclose( f );
- }
-
- DEFFUNC( void bin ( long len ) ) {
- assert( len > 0 );
- if ( len < BINS*BINSIZE ) histogram[len/BINSIZE]++;
- else histogram[BINS+1]++;
- }
-
- void process_samdat ( long buflen ) {
- register char *td, *endd;
- static char last = 0;
- static long abs_pos = 0, last_zero = 0;
-
- td = d;
- endd = &td[buflen];
-
- do {
- if ( (*td > 0) != (last > 0) ) {
- bin( abs_pos - last_zero );
- last_zero = abs_pos;
- }
- last = *td;
- abs_pos++;
- td++;
- } while ( td < endd );
- }